package ua.kpi_java_training.morochenets.module2;

import java.util.Scanner;

/**
 * Class for input initial conditions to simulate life in the pool
 *
 * @author Ari100tell
 * @data: 01.06.13
 * @time: 16:38
 */
public class InitialConditions {
    /**
     * @param Hint Prompt to enter the necessary data
     * @return Entered number
     */
    public int input(String Hint) {
        Scanner scanner = new Scanner(System.in);
        int readable = 0;
        boolean errorInput = false;
        do {
            try {
                System.out.println(Hint);
                readable = Integer.parseInt(scanner.nextLine());
                errorInput = false;
                errorInput = checkSign(readable, errorInput);
            } catch (Exception error) {
                System.out.println("Error: Enter another number");
                errorInput = true;
            }
        } while (errorInput);
        return readable;
    }

    /**
     * Check number positivity
     *
     * @param readable   Entered number
     * @param errorInput Variable for error monitoring
     * @return false if entered number is positive or zero and true if entered number negative
     */
    private boolean checkSign(int readable, boolean errorInput) {
        if (readable < 0) {
            errorInput = true;
        }
        return errorInput;
    }

    public int getNumberCycles() {
        return input("Input the number of cycles to simulate life in the pool:");
    }


    public int getLength() {
        return input("Enter length of pool:");
    }

    public int getWidth() {
        return input("Enter width of pool: ");
    }

    public int getNumberPredators() {
        return input("Enter the number of predators in the pool:");
    }

    public int getMaximumSpan() {
        return input("Enter the maximum displacement for a predator:");
    }

    public int getNumberPreys() {
        return input("Enter the number of preys in the pool:");
    }

    public int getTimeOfBirth() {
        return input("Enter the number of cycles for the birth of a new fish:");
    }
}
